package com.avecsys.quotemanager.utils;

import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import com.avecsys.quotemanager.constants.ApplicationConstants;
import com.avecsys.quotemanager.constants.BusinessCodes;
import com.avecsys.quotemanager.pojos.CountryMasterPojo;

public class SelectItemUtils
{

	/**
	 * Method to convert CountryMasterPojo instance to SelectItems
	 * 
	 * @param countryMasterPojoList
	 * @return List<SelectItem>
	 */
	public static List<SelectItem> convertCountryToSelectItems(
			List<CountryMasterPojo> countryMasterPojoList)
	{
		List<SelectItem> selectItemList = new ArrayList<SelectItem>();

		for (CountryMasterPojo countryMasterPojo : countryMasterPojoList)
		{
			SelectItem selectItem = new SelectItem(countryMasterPojo.getCode(),
					countryMasterPojo.getLongDesc());
			selectItemList.add(selectItem);
		}
		return selectItemList;
	}

	public static List<SelectItem> getAllEventTransactionStatusCodes()
	{
		List<String> transactionEventList = new ArrayList<String>();
		transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_PENDING);
		transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_BUYER_ACCEPT);
		transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_BUYER_AMEND);
		transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_BUYER_IGNORE);
		// TODO:
		// transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_SUPPLIER_ACCEPT);
		// transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_SUPPLIER_IGNORE);
		transactionEventList.add(BusinessCodes.QUOTE_EVENT_TRANSACTION_STATUS_SUPPLIER_REPLY);
		List<SelectItem> selectItemList = new ArrayList<SelectItem>();
		SelectItem selectItem = new SelectItem("", "All");
		selectItemList.add(selectItem);
		for (String tnxCode : transactionEventList)
		{
			selectItem = new SelectItem(tnxCode, MessageBoardUtil.getValue(
					FacesContext.getCurrentInstance(),
						ApplicationConstants.RESOURCE_BUNDLE_COMMON,
						"QUOTE_EVENT_TRANSACTION_STATUS_" + tnxCode,
						new Object[] {}));
			selectItemList.add(selectItem);
		}
		return selectItemList;
	}
}
